package com.ahuzdw.com;

/**
 * Author: Zhang Dongwei
 * Date: 2021/12/14 21:36
 */
public class test {
    public static void main(String[] args) {
        String s = "MCMXCIV";
        int l = s.length();
        int[] a = new int[l];
        int res = 0;
        for(int i=0;i<l;i++){
            a[i] = judge(s.charAt(i));
            System.out.println(a[i]);
            System.out.println(s.charAt(i));
            res += a[i];
            System.out.println(res);
        }

        for(int j=0;j<l;j++){
            if(s.charAt(j)=='I'&&s.charAt(j+1)=='V'){
                res -= 2;
            }else if(s.charAt(j)=='I'&&s.charAt(j+1)=='X'){
                res -= 2;
            }else if(s.charAt(j)=='X'&&s.charAt(j+1)=='L'){
                res -= 20;
            }else if(s.charAt(j)=='X'&&s.charAt(j+1)=='C'){
                res -= 20;
            }else if(s.charAt(j)=='C'&&s.charAt(j+1)=='D'){
                res -= 200;
            }else if(s.charAt(j)=='C'&&s.charAt(j+1)=='M'){
                res -= 200;
            }
        }
    }
    public static int judge(char c){
        if(c=='I'){
            return 1;
        }else if(c == 'V'){
            return 5;
        }else if(c == 'X'){
            return 10;
        }else if(c == 'L'){
            return 50;
        }else if(c == 'C'){
            return 100;
        }else if(c == 'D'){
            return 500;
        }else if(c == 'M'){
            return 1000;
        }else{
            return 0;
        }
    }

}

